﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Projet_IMA.Object3D;
using Projet_IMA.Base;

namespace Projet_IMA.Light
{
    public class LightDirectional : LightBase
    {
        private V3 direction;

        public LightDirectional(V3 direction, Couleur couleur) : base(couleur)
        {
            this.direction = direction;
            this.direction.Normalize();
        }

        public override Couleur ComputeDiffusColor(V3 normal, Couleur couleur)
        {
            return (this.couleur * couleur) * (direction * normal);
        }

        public override Couleur ComputeSpecularColor(V3 normal, Couleur couleur, V3 cameraDirection, int shininess)
        {
             float angleLightNormal = direction * normal;

             if (angleLightNormal > 0)
             {
                 V3 halfVector = direction + cameraDirection;
                 halfVector.Normalize();

                 float angleSpec = normal * halfVector;

                 if (angleSpec > 0.0)
                 {
                     float specularPower = MF.Pow(angleSpec, shininess);
                     return (this.couleur * couleur) * specularPower;
                 }
             }

             return new Couleur(0.0f, 0.0f, 0.0f);
        } 
    }
}
